﻿module Lhz.Page.DataManagement {
    export class UserAuthorization extends ManagementPage<Lhz.Entity.ServiceCenter.Authorization> {
        constructor() {
            super({
                targetName: "授权",
                serviceNo: "authorization",
                queryOperationNo: "queryByUserGuid",
                getQueryArguments: function (mp) {
                    var user: Lhz.Entity.ServiceCenter.User = mp.getDialogArguments();
                    return [user.Guid, ["User", "Service.Application", "Operation.Service.Application"]];
                },
                colModel: [
                    {
                        title: "授权类型", dataIndx: "AuthorizationType", width: "200", align: "center", render: function (event, ui) {
                            var item: Lhz.Entity.ServiceCenter.Authorization = event.rowData;
                            switch (item.AuthorizationType) {
                                case 0:
                                    return "应用授权";
                                case 1:
                                    return "服务授权";
                                case 2:
                                    return "操作授权";
                                default:
                                    return null;
                            }
                        }
                    },
                    {
                        title: "授权对象", dataIndx: "ObjectGuid", width: "200", align: "center", render: function (event, ui) {
                            var item: Lhz.Entity.ServiceCenter.Authorization = event.rowData;
                            return Lhz.Entity.ServiceCenter.Authorization.GetObjectName(item);
                        }
                    }
                ],
                detailPageUrl: "authorization-detail.html",
                width: 400,
                height: 300,
                getItemName: function (mp, item) {
                    return item.User.Name + "->" + Lhz.Entity.ServiceCenter.Authorization.GetObjectName(item);
                },
                getDetailArguments: function (ua: UserAuthorization, selectedItem: Lhz.Entity.ServiceCenter.DbEntity) {
                    return {
                        item: selectedItem,
                        dbOperation: ua.options.dbOperation,
                        userGuid: ua.getDialogArguments().Guid
                    };
                }
            });
        }
    }
    $(function () {
        new UserAuthorization();
    });
}
